#include <stdlib.h>

#include <debug.h>
#include <os_api.h>

#define TASK1_STACK_SIZE (10 * 1024)
#define TASK2_STACK_SIZE (4 * 1024)

static char _task_stack[TASK2_STACK_SIZE];

static void app_task1_stack_in_system_side(void *param)
{
    unsigned count = 0;

    while (1)
    {
        sleep(3); // 3 seconds
        count++;
        LOG_PRINTF("%s: count %u", __func__, count);
        LOG_PRINTF("%s: system heap total: %u free: %u", __func__, OsaGetDefaultMemPoolTotalSize(), OsaGetDefaultMemPoolFreeSize());
    }
}

static void app_task2_stack_in_app_side(void *param)
{
    unsigned count = 0;

    while (1)
    {
        sleep(3); // 3 seconds
        count++;
        LOG_PRINTF("%s: count %u", __func__, count);
    }
}

int main()
{
    int ret;
    OSTaskRef task1_ref, task2_ref; // because following task will never exit, so we do not use task handle, so we don't care it's handle

    ret = OSATaskCreate(&task1_ref, NULL, TASK1_STACK_SIZE, OS_APP_PRIORITY, "app1", app_task1_stack_in_system_side, NULL);
    ASSERT(ret == OS_SUCCESS);

    ret = OSATaskCreate(&task2_ref, _task_stack, TASK2_STACK_SIZE, OS_APP_PRIORITY, "app2", app_task2_stack_in_app_side, NULL);
    ASSERT(ret == OS_SUCCESS);

    return 0;
}
